package com.caldremch.calhttp.http;

import com.alibaba.fastjson.JSON;
import com.caldremch.calhttp.http.bean.BaseReq;
import com.caldremch.calhttp.http.bean.BaseReqData;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @author Caldremch
 * @date 2018-01-19 16:50
 * @describe
 **/
public class NetReqManager {

    public static final MediaType MEDIA_TYPE_PLAIN = MediaType.parse("text/plain;charset=utf-8");
    public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json;charset=utf-8");
    public static final MediaType MEDIA_TYPE_STREAM = MediaType.parse("application/octet-stream");
    public static final MediaType MEDIA_TYPE_FORM = MediaType.parse("application/x-www-form-urlencoded");

    //获取请求体
    public static RequestBody getReqData(BaseReqData reqObj) {
        BaseReq req = new BaseReq(reqObj);
        RequestBody requestBody
                = RequestBody.create(
                MEDIA_TYPE_JSON,
                JSON.toJSONString(req));
        return requestBody;
    }

}
